package com.bilibili.juc.locks;

import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @author zuife
 * @description
 * @since 2024-05-18 19:39:11
 */
public class LockDownGradingDemo {
    public static void main(String[] args) {
        ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
        ReentrantReadWriteLock.ReadLock readLock = readWriteLock.readLock();
        ReentrantReadWriteLock.WriteLock writeLock = readWriteLock.writeLock();
        // 正常 A B 两个线程
//        writeLock.lock();
//        System.out.println("---------写入");
//        writeLock.unlock();
//        // B
//        readLock.lock();
//        System.out.println("---------读取");
//        readLock.unlock();

        //本例，only one 同一线程
        writeLock.lock();
        /**
         * biz
         */
        readLock.lock();
        /**
         * biz
         */
        writeLock.unlock();

        readLock.unlock();
    }
}
